<template>
  <div class="register">    
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="login_box">
      <h3 class="login_title">欢迎注册</h3>
      <el-form-item label="用户名" prop="name">
        <el-input v-model="ruleForm.name" placeholder="请输入用户名"></el-input>
       </el-form-item>

       <el-form-item label="手机号" prop="phone">
        <el-input v-model="ruleForm.phone" placeholder="请输入手机号"></el-input>
       </el-form-item>
       <el-form-item label="邮箱" prop="email">
        <el-input v-model="ruleForm.email" placeholder="请输入邮箱"></el-input>
        </el-form-item>
      <el-form-item label="密码" prop="password">
       <el-input type="password" v-model="ruleForm.password" placeholder="请输入密码"></el-input>    
     </el-form-item>
      <el-form-item label="确认密码" prop="checkPass">
    <el-input type="password" v-model="ruleForm.checkPass" autocomplete="off" placeholder="请再次输入密码"></el-input>
  </el-form-item>
      <el-form-item class="login_btn">
         <el-button type="primary" @click="register('ruleForm')">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name:'login',
  data(){
     var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.ruleForm.password) {
          callback(new Error('两次输入密码不一致!'));
        } else {
          callback();
        }
      };
    return{
       ruleForm: {
          name:'',
          phone: '',
          email:'',
          password: '',
        checkPass: ''
        },
       rules: {
           name:[
            { message: '请输入用户名', trigger: 'blur' },
            { min: 3,  message: '长度大于3个字符', trigger: 'blur' }
           ],
          phone: [
            {  message: '请输入手机号', trigger: 'blur' },
            { min: 11, max: 11, message: '长度为11个字符', trigger: 'blur' }
          ],
           email: [
            {  message: '请输入邮箱', trigger: 'blur' }
          ],
          password: [
            { message: '请输入密码', trigger: 'blur' },
            { min: 3, max: 18, message: '长度在 3 到 18 个字符', trigger: 'blur' }
          ],
          checkPass: [
            { validator: validatePass, trigger: 'blur' }
          ],
      }
    }
  },
  methods:{
    register(){
   
    }
  }
}
</script>
<style>
.login_box {
    border: 1px solid #DCDFE6;
    width: 400px;
    margin: 80px auto;
    padding: 35px 35px 15px 35px;
    border-radius: 5px;
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    box-shadow: 0 0 20px #909399;
  }
.login_title {
    text-align: center;
    margin: 0 auto 40px auto;
    color: #303133;
  }
.login_btn{
  margin-left:15%;
}
</style>